package org.bigdata.framework.core.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import org.apache.poi.ss.formula.functions.T;
import org.bigdata.framework.core.log.annotation.SysLog;
import org.bigdata.framework.core.log.aop.LogAopAction;
import org.bigdata.framework.core.log.enums.BusinessType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 

public class DyLogAnnotations {
	
	public static void alterAnnotationOn(Method method, BusinessType businessType,String title) throws Exception {
		
		
		method.setAccessible(true);
		boolean methodHasAnno = method.isAnnotationPresent(SysLog.class); // 是否指定类型的注释存在于此元素上
		if (methodHasAnno) {
			// 得到注解
			SysLog methodAnno = method.getAnnotation(SysLog.class);
			// 修改
			InvocationHandler h = Proxy.getInvocationHandler(methodAnno);
			// annotation注解的membervalues
			Field hField = h.getClass().getDeclaredField("memberValues");
			// 因为这个字段是 private final 修饰，所以要打开权限
			hField.setAccessible(true);
			// 获取 memberValues
			Map<Object, Object> memberValues = (Map) hField.get(h);
			// 修改 description属性值
			memberValues.put("title",title);
			memberValues.put("businessType", businessType);
		}
		method.setAccessible(false);
	}
}
